<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>学籍信息</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/front/js/myValidate.js"></script> 
	<script type="text/javascript">
		$(document).ready(
				function() {
					$("#inputForm").validate(
							{
								rules : {
									id: {
										required : true,
										remote : {
											type:"POST",
											url:"${ctx}/ajax/check/schoolRollId.do",
											data:{
												id:function(){
													return $("#id").val();
												},
												oId:function(){
													return $("#oId").val();
												}
											}
										} 
									},
									idNumber: {
										digits:true
									},
									studentId: {
										required : true
									},
									classes: {
										required : true
									},
									grade: {
										digits:true,
										min: 0
									},
									category: {
										required : true
									},
									seatNumber: {
										digits:true
									},
									sortNumber: {
										digits:true
									}
								},
								messages : {
									id: {
										required : "请填写",
										remote:"已存在"
									},
									studentId: {
										required : "请选择"
									},
									classes: {
										required : "请选择"
									},
									idNumber: {
										digits:"只能为整数"
									},
									grade: {
										digits:"只能为整数",
										min: "必须大于0"
									},
									category: {
										required : "请选择"
									},
									seatNumber: {
										digits:"只能为整数"
									},
									sortNumber: {
										digits:"只能为整数"
									}
								},
								submitHandler : function(form) {
									loading('正在提交，请稍等...');
									form.submit();
								},
								errorContainer : "#messageBox",
								errorPlacement : function(error, element) {
									$("#messageBox").text("输入有误，请先更正。");
									if (element.is(":checkbox")
											|| element.is(":radio")
											|| element.parent().is(
													".input-append")) {
										error.appendTo(element.parent()
												.parent());
									} else {
										error.insertAfter(element);
									}
								}
							});
				     $("#category").change(function(){
				    	 var category=$("#category").val();
					     $.ajax({
					         type: "POST",
					         url: "${ctx}/ajax/get/gradeDict.do",
					         data: {"category":category},
					         dataType: 'json',
					         success: function(data) {
					               $("#grade").empty();
					               $("#grade").append("<option selected=\"selected\" value=\"\">请选择</option>" );
					               $.each(data, function(index,item){
					             		$("#grade").append('<option value='+item.value+'>'+item.label+'</option>');
					              }); 
					              /*  $("#s2id_grade").find("span[class='select2-chosen']").html("请选择"); */
					             }
					  		});
					     });
					//类别+年级级联到年级
					$("#grade").change(function(){
				        var studentId=$("#studentId").val();
				        var grade=$("#grade").val();
				     $.ajax({
				         type: "POST",
				         url: "${ctx}/ajax/get/class.do",
				         data: {"studentId":studentId,"grade":grade},
				         dataType: 'json',
				         success: function(data) {
				               $("#classes").empty();
				               $("#classes").append("<option selected=\"selected\" value=\"\">请选择</option>" );
				               $.each(data, function(index,item){
				             		$("#classes").append('<option value='+item.id+'>'+item.classes+'</option>');
				              }); 
				               $("#s2id_classes").find("span[class='select2-chosen']").html("请选择");
				             }
				  		});
				     });
				});
	
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<%-- <li><a href="${ctx}/dd/ddSchoolRoll/">学籍列表</a></li> --%>
		<li class="active"><a href="${ctx}/dd/ddSchoolRoll/form?id=${ddSchoolRoll.id}">学籍<shiro:hasPermission name="dd:ddSchoolRoll:edit">${not empty ddSchoolRoll.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="dd:ddSchoolRoll:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="ddSchoolRoll" action="${ctx}/dd/ddSchoolRoll/save" method="post" class="form-horizontal">
		<input type="hidden" id="oId" name="oId" value="${ddSchoolRoll.id}"/> 
		<sys:message content="${message}"/>
		<div class="control-group">
			<label class="control-label">
			<b style="color: red; font-size: large">*</b>学籍号：</label>
			<div class="controls">
				<form:input path="id" id="id" name="id" htmlEscape="false" maxlength="11" class="input-xlarge " required="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">学生：</label>
			<div class="controls">
				<%-- <form:input path="studentId" htmlEscape="false" maxlength="32" class="input-xlarge " readonly="true"
				value="${fns:getStudentName(ddSchoolRoll.studentId)}"/> --%>
				<form:select path="studentId" class="input-mini form-control required ">	
				                <form:option value="">请选择</form:option>	
								<form:options items="${fns:getStudentNameList()}" itemLabel="name"
									itemValue="id" htmlEscape="false" />
							</form:select> 
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">
			<b style="color: red; font-size: large">*</b>学号：</label>
			<div class="controls">
				<form:input path="idNumber" htmlEscape="false" maxlength="20" class="input-xlarge " required="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>类别：
			</label>
			<div class="controls">
				<form:select path="category"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getDictList('category')}"
						itemLabel="label" itemValue="value" htmlEscape="false" class="" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"> <b
				style="color: red; font-size: large">*</b>年级：
			</label>
			<div class="controls">
				<%-- <form:select path="grade"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getDictList('grade')}"
						itemLabel="label" itemValue="value" htmlEscape="false" class="" />
				</form:select> --%>
				<form:select path="grade" class="input-mini form-control required ">		
						<form:option value="" selected="selected">请选择</form:option> 
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">
			<b style="color: red; font-size: large">*</b>班级：</label>
			<div class="controls">
                <%-- <form:input path="classes" htmlEscape="false" placeholder="填入整数"  maxlength="20" class="input-xlarge " required="required"/> --%>
				<form:select path="classes" class="input-mini form-control required ">		
						<form:option value="0" selected="selected">请选择</form:option> 
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">入学日期：</label>
			<div class="controls">
				<input name="admissionDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate " required="required"
					value="<fmt:formatDate value="${ddSchoolRoll.admissionDate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">座号：</label>
			<div class="controls">
				<form:input path="seatNumber" htmlEscape="false" maxlength="11" class="input-xlarge "/>
			</div>
		</div>
		 <div class="control-group">
			<label class="control-label">排序号：</label>
			<div class="controls">
				<form:input path="sortNumber" htmlEscape="false" maxlength="11" class="input-xlarge " />
			</div>
		</div> 
		
		<div class="form-actions">
			<shiro:hasPermission name="dd:ddSchoolRoll:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>